import matplotlib.pyplot as plt
import numpy as np

# 数据准备
guidance_scale_categories = ['1', '0.5', '2']  
guidance_scale_gt = [3.91, 3.91, 3.91]
guidance_scale_hide = [4.22, 4.00, 4.37]
guidance_scale_reverse = [4.59, 4.19, 4.59]

step_size_categories = ['50', '100', '25']
step_size_gt = [3.91, 3.91, 3.91]
step_size_hide = [4.22, 4.14, 5.29]
step_size_reverse = [4.59, 3.91, 6.07]

scheduler_categories = ['PNDM', 'DDIM']
scheduler_gt = [3.91, 3.91]
scheduler_hide = [4.22, 4.28]
scheduler_reverse = [4.59, 4.29]

# 设置柱状图的宽度
bar_width = 0.2

def plot_bar_chart(categories, gt_values, hide_values, reverse_values, title, xlabel, filename):
    index = np.arange(len(categories))
    
    plt.figure(figsize=(8, 5))

    # 绘制分组柱状图
    plt.bar(index, gt_values, width=bar_width, label='GT', color='#6a9bdc')
    plt.bar(index + bar_width, hide_values, width=bar_width, label='Hide', color='#a5d080')
    plt.bar(index + 2 * bar_width, reverse_values, width=bar_width, label='Reverse', color='#ffcb9a')

    # 添加标签和标题
    plt.xlabel(xlabel, fontsize=12)
    plt.ylabel('Scores', fontsize=12)
    plt.title(title, fontsize=14)
    plt.xticks(index + bar_width, categories)  # 设置 x 轴刻度
    plt.legend(title='Method')  # 显示图例

    # 调整布局并保存图形
    plt.tight_layout()
    plt.savefig(filename)
    plt.show()

# 生成每张图
plot_bar_chart(guidance_scale_categories, guidance_scale_gt, guidance_scale_hide, guidance_scale_reverse,
                'Scores at Different Guidance Scales', 'Guidance Scale', 'save/guidance_scale_scores.png')

plot_bar_chart(step_size_categories, step_size_gt, step_size_hide, step_size_reverse,
                'Scores at Different Step Sizes', 'Step Size', 'save/step_size_scores.png')

plot_bar_chart(scheduler_categories, scheduler_gt, scheduler_hide, scheduler_reverse,
                'Scores for Different Schedulers', 'Scheduler', 'save/scheduler_scores.png')
